﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyWindowsMediaPlayer.Libs.ViewModel;
using System.Windows.Input;
using MyWindowsMediaPlayer.Libs.Mediator;

namespace MyWindowsMediaPlayer.ViewModels.Player
{
	public class PlayerViewModel : ViewModelBase
	{
		#region Members

		ICommand _PlayMedia;
		ICommand _StopMedia;
		ICommand _nextItem;
		ICommand _prevItem;

		bool _pause;

		Mediator _mediator;

		Uri _currentRead;

		#endregion

		#region Constructor

		public PlayerViewModel ( Mediator mediator )
		{
			this._mediator = mediator;
			this._mediator.Register(MediatorMessage.CurrentRead, param => { this._currentRead = (Uri)param;
																				 this.PlayCmd(); });
		}

		#endregion


		#region Accessors

		public ICommand PlayMedia
		{
			get
			{
				if (this._PlayMedia == null)
					this._PlayMedia = new RelayCommand(( ) => this.PlayCmd());
				return this._PlayMedia;
			}
		}

		public ICommand StopMedia
		{
			get
			{
				if (this._StopMedia == null)
					this._StopMedia = new RelayCommand(( ) => this.StopCmd());
				return this._StopMedia;
			}
		}

		public ICommand NextItem
		{
			get
			{
				if (this._nextItem == null)
					this._nextItem = new RelayCommand(( ) => this.NextCmd());
				return this._nextItem;
			}
		}

		public ICommand PrevtItem
		{
			get
			{
				if (this._prevItem == null)
					this._prevItem = new RelayCommand(( ) => this.PrevCmd());
				return this._prevItem;
			}
		}

		#endregion

		#region Commands

		private void PlayCmd ( )
		{
			this._mediator.NotifyColleagues(MediatorMessage.PlayItem, this._currentRead);
		}

		private void StopCmd ( )
		{
			this._mediator.NotifyColleagues(MediatorMessage.StopItem, null);
		}

		private void NextCmd ( )
		{
			this._mediator.NotifyColleagues(MediatorMessage.NextItem, null);
		}

		private void PrevCmd ( )
		{
			this._mediator.NotifyColleagues(MediatorMessage.PrevItem, null);
		}

		#endregion
	}
}
